package com.anysoft.adapter;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;

import com.anysoft.base.BaseFragment;

import java.util.ArrayList;

/**
 * Created by lty on 2017/11/8.
 */

public class BaseFragmentAdapter extends FragmentPagerAdapter {

    private ArrayList<Fragment> fragments;

    public BaseFragmentAdapter(FragmentManager fm) {
        super(fm);
        fragments = new ArrayList<>();
    }

    public void setData(ArrayList<BaseFragment> fragments) {
        if (fragments == null) {
            this.fragments.clear();
        } else {
            this.fragments.addAll(fragments);
        }
        notifyDataSetChanged();
    }

    @Override
    public Fragment getItem(int position) {
        return fragments.get(position);
    }

    @Override
    public int getCount() {
        return fragments.size();
    }
}
